
#include "ThreadPool.hpp"
#include "Task.hpp"
#include <iostream>
#include <ctime>


const string opers = "+-*/%";

using namespace std;

int main()
{
    srand((unsigned int)time(nullptr));

    std::cout << "process runn..." << std::endl;
    sleep(3);
    // ThreadPool<Task> *tp = new ThreadPool<Task>(5);
    ThreadPool<Task>::GetInstance()->Start();
    srand(time(nullptr) ^ getpid());

    int cnt = 5;
    while(true)
    {
        //1. 构建任务
        int x = rand() % 10 + 1;
        usleep(10);
        int y = rand() % 5;
        char op = opers[rand() % opers.size()];
        Task t(x, op, y);
        ThreadPool<Task>::GetInstance()->Push(t);
        //2. 交给线程池处理
        std::cout << "main thread make task: " << t.GetTask() << std::endl;

        sleep(1);
    }

    ThreadPool<Task>::DelInstance();
    return 0;
}
